package com.ymatou.iapi.userservice.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.SingleuserbriefBean;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.parameter.resp.SingleuserbriefResp;
import com.ymatou.iapi.userservice.service.SingleUserbriefCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.sqlwapper.JUserWapper;
/**
*根据userid批量查询用户概要信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_Singleuserbrief{
	private static SingleuserbriefBean singleuserbriefBean;
	private static SingleUserbriefCall singleuserbriefCall;
	private static JUserWapper jUserWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据userid批量查询用户概要信息");
	}

	@Before
	public void caseUp() {
		singleuserbriefBean=new SingleuserbriefBean();
		singleuserbriefCall=new SingleUserbriefCall();
		jUserWapper=new JUserWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(singleuserbriefCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Singleuserbrief_001() {
		Logger.start(true,"输入正确用户id,返回成功");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			//Userinfo model=jUserWapper.selectTop1Userinfo();
			singleuserbriefBean.setUserId(uid);
			singleuserbriefBean.setReqDomain("www.ymatou.com");
			singleuserbriefCall.setData(singleuserbriefBean);
			singleuserbriefCall.callService();	
			verifyOk(uid);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_Singleuserbrief_002() {
		Logger.start(false,"输入不存在的用户id,返回失败");
		try {
			singleuserbriefBean.setUserId(999999999);
			singleuserbriefBean.setReqDomain("www.ymatou.com");
			singleuserbriefCall.setData(singleuserbriefBean);
			singleuserbriefCall.callService();	
			verifyErr();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_Singleuserbrief_003() {
		Logger.start(false,"不输入用户id,返回失败");
		try {
			singleuserbriefBean.setUserId(0);
			singleuserbriefBean.setReqDomain("www.ymatou.com");
			singleuserbriefCall.setData(singleuserbriefBean);
			singleuserbriefCall.callService();	
			verifyErr();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	/**
	 * 验证成功
	 * @param model
	 */
	public void verifyOk(Integer uid)
	{
		Userinfo model=jUserWapper.selectUserinfoByUid(uid).get(0);
		SingleuserbriefResp resp=singleuserbriefCall.getResultData();
		Logger.verifyEquals(true, resp.getSuccess(), "验证Success");
		Logger.verifyEquals(200, resp.getResponseCode(), "验证ResponseCode");
		Logger.verifyEquals(model.getUserId(), resp.getResult()[0].getuserId(), "验证userId");
		Logger.verifyEquals(model.getLoginId(), resp.getResult()[0].getloginId(), "验证loginId");
		Logger.verifyEquals(model.getLoginMail(), resp.getResult()[0].getloginMail(), "验证loginMail");
		Logger.verifyEquals(model.getLoginMobile(), resp.getResult()[0].getloginMobile(), "验证loginMobile");
		if(model.getUserType()!=null&&resp.getResult()[0].getuserType()!=null){
			Logger.verifyEquals(model.getUserType(), resp.getResult()[0].getuserType(), "验证userType");
		}
		Logger.verifyEquals(model.getUserLevel().toString(), resp.getResult()[0].getuserLevel(), "验证userLevel");
		Logger.verifyEquals(model.getRegisterTime(), resp.getResult()[0].getregisterTime(), "验证registerTime");
		Logger.verifyEquals(model.getLoginPassword(), resp.getResult()[0].getloginPwd(), "验证loginPwd");
		Logger.verifyEquals(model.getTradingPassword(), resp.getResult()[0].gettradingPwd(), "验证tradingPwd");
	}
	/**
	 * 验证失败
	 * @param model
	 */
	public void verifyErr()
	{
		SingleuserbriefResp resp=singleuserbriefCall.getResultData();
		Logger.verifyEquals(true, resp.getSuccess(), "验证Success");
		Logger.verifyEquals(100001, resp.getResponseCode(), "验证ResponseCode");
		Logger.verifyIsContains("未查询到用户", resp.getLastErrorMessage(), "验证LastErrorMessage");
	}
}